---
title: "Yale Climate Opinion data"
author: "Nicolas Wittstock"
date: "2023-06-13"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

rm(list = ls())
cat("\014")
```


```{r}
library(vroom)
library(tidyverse)
library(haven)
library(ggthemes)
```


*Create Figure 1*

```{r}
data <- vroom("yale_climate_opinion_data.csv")

head(data)

data <- data %>%
  filter(year == 2020) %>%
  dplyr::select(cty_fips, countyname, statename, year, CO2limits, fundrenewables,
                supportRPS, regulate)
```

*Relative Rurality at the county level from Waldorf and Kim*

```{r}
irr <- vroom("IRR_2000_2020.csv")

head(irr)

irr <- irr %>%
  rename(cty_fips = FIPS2020) %>%
  dplyr::select(cty_fips, IRR2020
                
)

data <- left_join(data, irr, by = "cty_fips")
```

*Visualization*

```{r}

library(scales)

data %>%
  ggplot(aes(x = IRR2020, y = supportRPS / 100)) + 
  geom_point(size = 0.5, alpha = 0.3) + 
  geom_smooth(method = "lm") + 
  theme_clean() + 
  xlab("Relative Rurality in 2020") + 
  ylab("Level of Support for RPS in 2020") + 
  scale_y_continuous(labels = label_percent())


ggsave("support.rps.png", 
       width = 8, height = 8/1.618, units = "in")


cor(data$IRR2020, data$supportRPS, use = "complete.obs")
```



